<?php
    namespace app\common\lib;
    class InnerCurl {
        public static function reward($target, $data) {
            if(is_array($data)) {
                if(isset($data['id'])) {
                    $data['id'] = $data['id'] * 23;
                    $data['id'] = dechex($data['id']);
                    $data['key'] = strrev($data['id']);
                    unset($data['id']);
                }
                
                //$data = json_encode($data);
            }
            
            return self::ch('reward/' . $target, $data);
        }
        
        public static function copyChat($data) {
            return self::ch('publish', $data);
        }
        
        private static function ch($target, $data) {
            $ch = curl_init('http://127.0.0.1:9999/' . $target);
            curl_setopt($ch, CURLOPT_POST, 1); //设置为POST方式
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//POST数据
            
            $body = curl_exec($ch);
            curl_close($ch);
            return $body;
        }
    }